home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 50 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: Informatik.Uni-Dortmund.DE!news
  2. From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab)
  3. Newsgroups: comp.std.c
  4. Subject: Re: sizeof(1L) in preprocesor;How to tell sizeof(double)>sizeof(long) ?
  5. Date: 08 Jan 1996 13:58:51 +0100
  6. Organization: Dortmund University, Germany
  7. Sender: schwab@lamothe.informatik.uni-dortmund.de
  8. Message-ID: <vyzd98ug7w4.fsf@lamothe.informatik.uni-dortmund.de>
  9. References: <sc3f9vb6gk.fsf@lns101.lns.cornell.edu>
  10.     <1996Jan5.094122.16151@sq.com>
  11. Reply-To: schwab@issan.informatik.uni-dortmund.de
  12. NNTP-Posting-Host: lamothe.informatik.uni-dortmund.de
  13. In-reply-to: msb@sq.com's message of Fri, 5 Jan 1996 09:41:22 GMT
  14. X-Newsreader: Gnus v5.0.13
  15.  
  16. In article <1996Jan5.094122.16151@sq.com>, msb@sq.com (Mark Brader) writes:
  17.  
  18. |> Nobuhiko Katayama (nk@lns598.lns.cornell.edu) writes:
  19. |>> is there any portable way to tell whether
  20. |>> long is longer(shorter) than double in preprocessor stage ?
  21.  
  22. |> I can't think of any way.
  23.  
  24. |> You *can* use the various characteristics defined in <limits.h> and
  25. |> <float.h>, as explained in section 5.2.4.2 (2.2.4.2), to find out
  26. |> various information about the types.  In particular, if what you
  27. |> really want is to choose whichever of the two types can hold the
  28. |> larger exact integer value, then in practice you need only do:
  29.  
  30. |>     #include <limits.h>
  31. |>     #include <float.h>
  32. |>     #if LONG_MAX * DBL_EPSILON > 1
  33. |>         typedef long mytype;
  34. |>         #define mytype_format "%ld" /* for printf */
  35. |>     #else
  36. |>         typedef double mytype;
  37. |>         #define mytype_format "%f"
  38. |>     #endif
  39.  
  40. This doesn't work as floating point numbers aren't allowed in #if
  41. expressions.  It must be written using a runtime check (which will
  42. probably optimized out by the compiler).
  43. -- 
  44. Andreas Schwab                                      "And now for something
  45. schwab@issan.informatik.uni-dortmund.de              completely different"
  46.